<?php
#============================
#	Filename: msglist.qgmod.php
#	Note	: 列表读取
#	Version : 2.0
#	Author  : ovsexia
#	Update  : 2017-8-23
#============================
global $FS,$DB,$PA,$prefix,$bi;
if($ispic)
{
	$md5 = md5(TemplateID."_".$cateid."_".$length."_".$orderby."_1_".$limit);
}
else
{
	$md5 = md5(TemplateID."_".$cateid."_".$length."_".$orderby."_0_".$limit);
}
$cache_file = "data/cache/list_".$md5.".php";#[缓存文件]
$check_status = false;
if($iscache)
{
	$check_status = CheckCache($cache_file);#[判断缓存文件的存储状态]
}
if($check_status)
{
	include_once($cache_file);
	unset($cache_file);
	return $list;
}
#[取得当前分类的信息]
$rs = $DB->qgGetOne("SELECT catename".$bi." FROM ".$prefix."category WHERE id='".$cateid."'");

#推荐
$tuijian ="AND isrecommend=".$tuijian."";

if(!$rs)
{
	unset($cache_file);
	return false;
}
$list["catename"] = $rs["catename".$bi];
$list["id"] = $cateid;
$list["cateid"] = $cateid;
$list["url"] = "list.php?id=".$cateid;
unset($rs);
if($ispic)
{
	$sql = "SELECT c.catename,c.catename_en,c.catename_ft,m.*,u.filename AS u_filename,u.thumbfile AS u_thumbfile,u.markfile AS u_markfile,u.folder AS u_folder,u.filetype AS u_filetype FROM ".$prefix."msg AS m,".$prefix."category AS c,".$prefix."upfiles AS u WHERE (c.id='".$cateid."' OR c.rootid='".$cateid."' OR c.parentid='".$cateid."') AND m.thumb=u.id AND m.ifcheck='1' AND m.additonid='0' AND m.cateid=c.id ".$tuijian."";
}
else
{
	$sql = "SELECT c.catename,c.catename_en,c.catename_ft,m.*,u.filename AS u_filename,u.thumbfile AS u_thumbfile,u.markfile AS u_markfile,u.folder AS u_folder FROM ".$prefix."category AS c,".$prefix."msg AS m LEFT JOIN ".$prefix."upfiles AS u ON m.thumb=u.id WHERE  (c.id='".$cateid."' OR c.rootid='".$cateid."' OR c.parentid='".$cateid."') AND m.ifcheck='1' AND m.additonid='0' AND m.cateid=c.id ".$tuijian."";
}

$sqlorder = "SELECT * FROM ".$prefix."category AS c WHERE id ='".$cateid."'";
$listorder = $DB->qgGetOne($sqlorder);

$query = "SELECT * FROM ".$prefix."category WHERE parentid='".$cateid."' AND status='1' AND language='".LANGUAGE_ID."' ORDER BY taxis ASC,id DESC";
$result=mysql_query($query);
$number=mysql_num_rows($result);

$sql .= " order by ";
if($orderby2)
{
	$orderby_w = $orderby2.",";
}
if ($listorder["parentid"]!=0 and $number > 0)
{
	$sql .= $orderby_w."c.taxis asc,m.sortid asc,m.id desc";
}
elseif($listorder["parentid"]==0 and $number > 0)
{
	$sql .= $orderby_w."m.allsortid asc,m.id desc";
}
else
{
	$sql .= $orderby_w."m.allsortid asc,m.id desc";
}

$sql .= " LIMIT 0,".$limit;

$rs_list = $DB->qgGetAll($sql,true);

if(!$rs_list)
{
	unset($sql,$cache_file);
	return false;
}
$rslist = array();
$i = 1;
foreach($rs_list AS $key=>$value)
{					
	$sql = "SELECT * FROM ".$prefix."msg_content WHERE id='".$value["id"]."' ";
	$rsc = $DB->qgGetOne($sql);
	/*清除标签*/
	$sql = "SELECT * FROM ".$prefix."msg_content where id =".$value["id"];
	$rs = $DB->qgGetOne($sql);
	$value["content"] = $rs["content".$bi];
	$value["cut_content"] = strip_tags($value["content"]);
	$value["cut_content"] = CutString(str_replace(array("<p>","</p>","<div>","</div>","<br />","&nbsp;","　"),array("","","","","","",""),$value["cut_content"]),$words);
	
	$value["folder"] = $value["u_folder"];
	$value["filename"] = $value["u_filename"];
	$value["markfile"] = $value["u_markfile"];
	$value["thumbfile"] = $value["u_thumbfile"];
	//裁剪图片
	$sysimg = $PA->sysize($value["cateid"]);
	$swidth = $sysimg["width"];
	$sheight = $sysimg["height"];
	$value["cutimg"] = "images.php?imgurl=".base64_encode($value["folder"].$value["filename"])."&swidth=".$swidth."&sheight=".$sheight;
	unset($value["u_folder"],$value["u_filename"],$value["u_markfile"],$value["u_thumbfile"]);

	$value["catename"] = $value["catename".$bi];
	$value["subject"] = $value["subject".$bi];	
	$value["cut_subject"] = CutString($value["subject"],$length);
	
	#[获取自定义字段]
	$value["fieldlist"] = $PA->fieldlist($value["id"]);
	if($value["fieldlist"])
	{
		foreach($value["fieldlist"] AS $key2=>$value2)
		{
			$value[$value2["sign"]] = $value2["field_content"];
		}
	}
	
	#[日期转换]
	$value["year"] = date("Y",$value["postdate"]);
	$value["day"] = date("d",$value["postdate"]);
	$value["month"] = monthc(date("m",$value["postdate"]),"min"); //[min] or [ful]

	//首项尾项
	if($i==1)
	{
		$value["first"] = true;
	}
	if($i==count($rs_list))
	{
		$value["last"] = true;
	}
	$value["row_index"] = $i;
	$rslist[] = $value;
	$i++;
}

$msglist = _____QGMODULE_CLEARUP_LIST($rslist,$length,true);
$list["list"] = $msglist;

$FS->qgWrite($list,$cache_file,"list");
unset($rslist,$msglist,$cache_file);
return $list;
?>